﻿using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FirstHomeWork.Thread.Common
{
    public class CustomConfigManager
    {
        public static string GetConfig(string key)
        {
            var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
            IConfigurationRoot configuration = builder.Build();
            string configValue = configuration.GetSection(key).Value;
            return configValue;
        }

        /// <summary>
        /// 获取所有的数据
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static List<string> GetEventList(string key)
        {
            string strEvent = GetConfig(key);
            if (string.IsNullOrWhiteSpace(strEvent))//读取到配置文件以后，可以判断一下，如果配置文件不准确，直接抛出异常---不要掩盖错误；
            {
                throw new Exception("兄嘚~配置文件有问题耶~");
            }
            return strEvent.Split(",").ToList();
        }
    }
}
